#define _CRT_SECURE_NO_WARNINGS 1
#pragma warning(disable:6031)

#include "Heap.h"
#include <time.h>

static void Test1(void)
{
	Heap hp;
	HeapDataType a[] = { 1,13,23,2,7,9,10,25,14,11,8,15 };
	HeapInit(&hp, a, sizeof(a) / sizeof(a[0]));
	HeapPrint(&hp);
	HeapPush(&hp, 0);
	HeapPrint(&hp);
	HeapPop(&hp);
	HeapPrint(&hp);
	HeapPush(&hp, 6);
	HeapPrint(&hp);
	HeapPop(&hp);
	HeapPrint(&hp);
}
static void Test2(void)
{
	Heap hp;
	HeapInit(&hp, NULL, 0);
	HeapPrint(&hp);
	HeapPush(&hp, 0);
	HeapPush(&hp, 4);
	HeapPush(&hp, 7);
	HeapPush(&hp, 3);
	HeapPush(&hp, 11);
	HeapPush(&hp, -1);
	HeapPrint(&hp);
	HeapPop(&hp);
	HeapPrint(&hp);
	HeapDestroy(&hp);
}

static void Test3(void)
{
	Heap hp;
	HeapInit(&hp, NULL, 0);
	HeapPush(&hp, 2);
	HeapPush(&hp, 15);
	HeapPush(&hp, 8);
	HeapPush(&hp, 9);
	HeapPush(&hp, 0);
	HeapPush(&hp, 7);
	HeapPush(&hp, 11);
	HeapPrint(&hp);
	printf("%d\n", HeapTop(&hp));
	HeapPop(&hp);
	printf("%d\n", HeapTop(&hp));
	HeapDestroy(&hp);
}

static void Test4(void)
{
	Heap hp;
	HeapInit(&hp, NULL, 0);
	HeapPush(&hp, 2);
	HeapPush(&hp, 15);
	HeapPush(&hp, 8);
	HeapPush(&hp, 9);
	HeapPush(&hp, 0);
	HeapPush(&hp, 7);
	HeapPush(&hp, 16);
	HeapPush(&hp, 10);
	HeapPush(&hp, 111);
	HeapPush(&hp, 167);
	HeapPush(&hp, 190);
	HeapPush(&hp, 66);
	HeapPrint(&hp);
	Heapsort(&hp);
	HeapPrint(&hp);
	HeapDestroy(&hp);
}

static void FileCreat(char* filename, int N)
{
	assert(filename);

	FILE* pfin = fopen(filename, "w");
	if (pfin == NULL)
	{
		perror("fopen");
		exit(-1);
	}
	srand((unsigned int)time(NULL));

	while (N--)
	{
		fprintf(pfin, "%d ", rand() % 10000);
	}

	fclose(pfin);
	pfin = NULL;
}

static void Test5(void)
{
	//FileCreat("text.txt", 10000);
	HeapToPKPrint("text.txt", 10);
}

int main()
{
	//Test1();
	//Test2();
	//Test3();
	//Test4();
	Test5();
	return 0;
}